﻿// -----------------------------------------------------------------------
// <copyright file="FluentSerializableAttribute.cs" company="none">
// Copyright (c) 2012 M. Alberti, xanatos(at)live.it
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
// </copyright>
// -----------------------------------------------------------------------

namespace FluentSerializer
{
    using System;
    using System.Linq.Expressions;
    using FluentStatement.Utilities;

    /// <summary>
    /// 
    /// </summary>
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct)]
    public class FluentSerializableAttribute : Attribute
    {
        /// <summary>
        /// 
        /// </summary>
        public readonly Type Serializer;

        /// <summary>
        /// 
        /// </summary>
        public readonly Type CollectionHelper;

        /// <summary>
        /// 
        /// </summary>
        protected readonly Func<Expression> GetSerializer;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="serializer"></param>
        public FluentSerializableAttribute(Type serializer)
            : this(serializer, null)
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="serializer"></param>
        /// <param name="collectionHelper"></param>
        public FluentSerializableAttribute(Type serializer, Type collectionHelper)
        {
            if (serializer == null)
            {
                throw new ArgumentNullException("type");
            }

            if (serializer.GetInterfaces(typeof(ISerializer<,>)).Length == 0)
            {
                throw new ArgumentException("serializer");
            }

            if (collectionHelper != null && !typeof(ICollectionHelper).IsAssignableFrom(collectionHelper))
            {
                throw new ArgumentException("collectionHelper");
            }

            this.Serializer = serializer;
            this.CollectionHelper = collectionHelper;
        }
    }
}